package cn.net.withub.dataCollector.common.utils;

import java.util.Properties;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component(value="commonProperties")
public class CommonProperties {
    /**
     *系统名称
     */
    @Value("${SYSTEM_MC}")
    public String SYSTEM_MC;

    /**
     *系统资源id
     */
    @Value("${XTPT_BUSINESS_ID:''}")
    public String XTPT_BUSINESS_ID;

    /**
     *系统平台地址
     */
    @Value("${XTPT_WEBSERVICE_URL:''}")
    public String XTPT_WEBSERVICE_URL;

    /**
     *地区
     */
    @Value("${FY_DQ:''}")
    public String FY_DQ;

    /**
     *当前地区高院
     */
    @Value ("${FY_DQGY:''}")
    public String FY_DQGY;

    //FTP地址
    @Value("${ftp.address}")
    public String ftpAddress;
    //FTP 端口
    @Value("${ftp.port}")
    public String ftpPort;
    //ftp用户名
    @Value("${ftp.userName}")
    public String ftpUserName;
    //ftp密码
    @Value("${ftp.password}")
    public String ftpPassword;

    //ftp下载到本地文件路径
    @Value("${ftp.download.path}")
    public String ftpDownloadPath;

    public String getXTPT_BUSINESS_ID() {
        return XTPT_BUSINESS_ID;
    }

    public void setXTPT_BUSINESS_ID(String XTPT_BUSINESS_ID) {
        this.XTPT_BUSINESS_ID = XTPT_BUSINESS_ID;
    }

    public String getXTPT_WEBSERVICE_URL() {
        return XTPT_WEBSERVICE_URL;
    }

    public void setXTPT_WEBSERVICE_URL(String XTPT_WEBSERVICE_URL) {
        this.XTPT_WEBSERVICE_URL = XTPT_WEBSERVICE_URL;
    }

    public String getSYSTEM_MC() {
        return SYSTEM_MC;
    }

    public void setSYSTEM_MC(String SYSTEM_MC) {
        this.SYSTEM_MC = SYSTEM_MC;
    }

    public String getFY_DQ() {
        return FY_DQ;
    }

    public void setFY_DQ(String FY_DQ) {
        this.FY_DQ = FY_DQ;
    }

    public String getFY_DQGY() {
        return FY_DQGY;
    }

    public void setFY_DQGY(String FY_DQGY) {
        this.FY_DQGY = FY_DQGY;
    }

    //获取class路径
    public static String getClassPath(){
        String path = CommonProperties.class.getResource("/").getPath();
        path = path.substring(1,path.length()-1);//去掉前后两个斜杠/

        Properties prop = System.getProperties();

        String os = prop.getProperty("os.name");
        //判断操作系统
        if(os.startsWith("win") || os.startsWith("Win")){
            //windows
        }else{
            //other
            path = "/"+path;
        }

        return path;
    }
    public static String getWebRootPath(){
        String path = getClassPath();
        if(path.indexOf("target")>-1){
            path = path.substring(0,path.length()-"/target/classes".length())+"";///src/main/webapp
        }else if(path.indexOf("WEB-INF")>-1){
            path = path.substring(0,path.length()-"/WEB-INF/classes".length());
        }

        Properties prop = System.getProperties();

        String os = prop.getProperty("os.name");
        //判断操作系统
        if(os.startsWith("win") || os.startsWith("Win")){
            //windows
        }else{
            //other
            path = "/"+path;
        }

        return path;
    }

    /**
     * 获取config.properties中参�?
     * @author LiuYang
     * @param paramName
     * @return
     * @throws Exception
     */
    public static String getConfigProperties(String paramName){
        String paramValue = "";
        try{
            String fliePath= CommonProperties.getClassPath()+"/"+"config.properties"; //jdbc.properties PathUtil.getClassPath()+"/"+
            PropertiesConfiguration p = new PropertiesConfiguration(fliePath);
            paramValue = p.getString(paramName);
        }catch(Exception e){
            e.printStackTrace();
        }
        return paramValue;
    }
}
